﻿$(document).ready(function () {
    $(".hidden").hide();
    $(".hidden_new").hide();
    $(".showInfor").click(function () {
        $("#info_" + $(this).attr("id")).toggle("slow");
    })

    $("#btn_add_room").click(function () {
        $("#info_new").toggle("slow");
    })

    $(".search").live("click", function () {
        var maDay = $("#maDay").val();
        var maTang = $("#maTang").val();
        var dataString = "maTang=" + maTang + "&maDay=" + maDay
        $.ajax({
            type: "GET",
            url: "Search_Room",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#results").html(data).hide().fadeIn();
                $(".hidden").hide();
                $(".hidden_new").hide();
                $(".showInfor").click(function () {
                    $("#info_" + $(this).attr("id")).toggle("slow");
                })
                $("#btn_add_room").click(function () {
                    $("#info_new").toggle("slow");
                })
            }
        });
    });
    

    $(".update").live("click", function () {
        var maPhong = $(this).attr("id");
        var maHang = $("#maHang" + maPhong).val()
        var maLoai = $("#maLoai" + maPhong).val()
        var maTang = $("#maTang" + maPhong).val()
        var maDay = $("#maDay" + maPhong).val()
        maPhong = maPhong.substr(1);
        var dataString = "maLoai=" + maLoai + "&maHang=" + maHang + "&maTang=" + maTang + "&maDay=" + maDay + "&maPhong=" + maPhong
        $.ajax({
            type: "GET",
            url: "Update_Room",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#notice_" + maPhong).html(data).hide().fadeIn();
                setTimeout(function () {
                    $("#notice_" + maPhong).fadeOut("slow", function () {
                        //$("#notice" + maLoai).remove();
                    });
                }, 2000);
            }
        });
    });


    $(".delete").live("click", function () {
        var maPhong = $(this).attr("id");
        var dataString = "maPhong" + maPhong
        maPhong = maPhong.substr(1);
        $.ajax({
            type: "GET",
            url: "Delete_Room",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#notice_" + maPhong).html(data).show();
                setTimeout(function () {
                    $("#notice_" + maPhong).fadeOut("slow", function () {
                        //$("#notice" + maLoai).remove();
                    });
                }, 2000);
                location.reload();
            }
        });
    });


    $(".add").live("click", function () {
        var maLoai = $("#maLoai_new").val();
        var maHang = $("#maHang_new").val();
        var maTang = $("#maTang_new").val();
        var maDay = $("#maDay_new").val();
        var dataString = "maLoai=" + maLoai + "&maHang=" + maHang + "&maTang=" + maTang + "&maDay=" + maDay
        $.ajax({
            type: "GET",
            url: "Add_Room",
            data: dataString,
            dataType: 'html',
            success: function (data) {
                $("#notice_new").html(data).show()
                setTimeout(function () {
                    $("#notice_new").fadeOut("slow", function () {
                        //$("#notice" + maLoai).remove();
                    });
                }, 2000);
                location.reload();
            }
        });
    });


});